package com.alan.base.utils;

import android.util.Log;

import com.alan.base.App;
import com.alan.base.config.Config;
import com.alan.base.config.FileLogManager;

public class Logger {

    public static void d(String message) {
        if (isEnable()) {
            Log.d(tag(), content(message));
        }
    }

    public static void v(String message) {
        if (isEnable()) {
            Log.v(tag(), content(message));
        }
    }

    public static void e(String message) {
        if (isEnable()) {
            Log.e(tag(), content(message));
        }
    }

    public static void w(String message) {
        if (isEnable()) {
            Log.e(tag(), content(message));
        }
    }

    public static void i(String message) {
        if (isEnable()) {
            Log.e(tag(), content(message));
        }
    }

    public static void f(String message) {
        if (Config.getInstance().isLogF()&& App.getInstance().getApplication()!=null) {
            FileLogManager.getInstance().addContent(message);
        }
    }

    public static void writeLogImmediately(String message) {
        if (Config.getInstance().isLogF()&& App.getInstance().getApplication()!=null) {
            FileLogManager.getInstance().write(message);
        }
    }

    public static void d(String tag, String message) {
        d(tag + " " + message);
    }

    public static void d(int val) {
        d(String.valueOf(val));
    }

    public static void v(int val) {
        v(String.valueOf(val));
    }

    public static void e(int val) {
        e(String.valueOf(val));
    }

    public static void w(int val) {
        w(String.valueOf(val));
    }

    public static void i(int val) {
        i(String.valueOf(val));
    }

    public static void d(boolean val) {
        d(String.valueOf(val));
    }

    public static void v(boolean val) {
        v(String.valueOf(val));
    }

    public static void e(boolean val) {
        e(String.valueOf(val));
    }

    public static void w(boolean val) {
        w(String.valueOf(val));
    }

    public static void i(boolean val) {
        i(String.valueOf(val));
    }

    public static void d(long val) {
        d(String.valueOf(val));
    }

    public static void v(long val) {
        v(String.valueOf(val));
    }

    public static void e(long val) {
        e(String.valueOf(val));
    }

    public static void w(long val) {
        w(String.valueOf(val));
    }

    public static void i(long val) {
        i(String.valueOf(val));
    }

    public static void error(Throwable e) {
        if (Config.getInstance().isLogE()) {
            Log.e(tag(), Log.getStackTraceString(e));
        }
    }

    private static boolean isEnable() {
        return Config.getInstance().isLog();
    }

    private static String tag() {
        return Config.getInstance().getLogTag();
    }

    private static String content(String msg) {
        return " [" + "thread name:" + Thread.currentThread().getName() + "] " + msg;
    }

}
